package com.geezdata.cps.base.enums;

public enum ErrorCode implements BaseEnum {
	SUCCESS(1000000, "SUCCESS"),
	MY_EXCEPTION(2000000, "MY_EXCEPTION"),
	INVALID_PARAMS(3000000, "非法参数"),
	NONEXISTENT_USERNAME(3000001, "用户名不存在"),
	INVALID_DDK_GOODS_ID(3000002, "非多多客商品"),
	HTTP_EXCEPTION(4000000, "HTTP_EXCEPTION"),
	INTERNAL_SERVER_ERROR(5000000, "INTERNAL_SERVER_ERROR"),
	XML_PARSE_EXCEPTION(6000000, "XML_PARSE_EXCEPTION"),
	INVALID_SESSION(7000000, "INVALID_SESSION"),
	INVALID_AUTHORIZATION(8000000, "INVALID_AUTHORIZATION"),
	INVALID_SESSIONKEY(9000000, "sessionKey过期解密失败"),
	INVALID_CODE(10000000, "code过期，获取unionId失败"),
	SHARER_NULL(10000001, "用户不存在"),
	TASK_CANCEL(10001000, "任务已取消");
	
	private int code;
	private String desc;
	
	private ErrorCode(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }
	
	public int getCode() {
        return this.code;
    }
	
	public String getDesc() {
        return this.desc;
    }
	
	public static String getDesc(int code) {
        for (ErrorCode errorCode : ErrorCode.values()) {
        	if (code == errorCode.getCode()) {
                return errorCode.getDesc();
            }
        }
        
        throw new IllegalArgumentException("code not exist.");
    }
	
	public static ErrorCode getByCode(int code) {
        for (ErrorCode errorCode : ErrorCode.values()) {
            if (code == errorCode.getCode()) {
                return errorCode;
            }   
        }   
        
        throw new IllegalArgumentException("code not exist.");
    }   
}
